package com.example.petshop.controller;

import com.example.petshop.entity.Pet;
import com.example.petshop.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pet")
public class PetController {

    @Autowired
    private PetService petService;

    @GetMapping("/getall")
    public List<Pet> getAllPets() {
        return petService.getAllPets();
    }

    @GetMapping("/{petId}")
    public Pet getPetById(@PathVariable int petId) {
        return petService.getPetById(petId);
    }
    @PostMapping("/create")
    public ResponseEntity<Void> createPet(@RequestBody Pet pet) {
        System.out.println(pet);
        // 调用服务层的方法来创建新的商店
        petService.createPet(pet);
        return ResponseEntity.ok().build();
    }
    @DeleteMapping("/delete/{petId}")
    public ResponseEntity<Void> deletePet(@PathVariable Integer petId) {
        // 调用服务层的方法来删除商店
        petService.deletePet(petId);
        return ResponseEntity.ok().build();
    }

    @PutMapping("/update")
    public ResponseEntity<Void> updatePet(@RequestBody Pet pet) {
        // 调用服务层的方法来更新商店
        petService.updatePet(pet);
        return ResponseEntity.ok().build();
    }
}